import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { config } from '../../../shared/smartadmin.config';
import { Router, ActivatedRoute } from "@angular/router"; //路由引入

declare var $: any;
@Component({
	selector: 'sa-areaCount',
	templateUrl: './areaCount.component.html',
})
export class AreaCountComponent implements OnInit {
	tableData: any = []; //table数据
	totalCount: number = 0; //分页总条数
	curPage: number = 1; //分页当前页
	pageSize: number = 10; //内置的分页每页条数
	searchKey: string = ''; //搜索keyword

	carNumber = ''; //车牌号码
	deviceId: string = ''; //设备ID
	companyName: string = ''; //公司名称
	companyId: string = '';
	areaName: string = '';//区域名称
	startTime: string = ''; //开始时间
	endTime: string = ''; //结束时间
	
	allAreaList:any=[];
	allStationList:any=[];
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {}
	getSelectTableTime(time) {
		this.startTime = time.startTime;
		this.endTime = time.endTime;
	}
	initTime(){
		let nowTime= new Date();
		this.endTime=common.getTimeMmss(nowTime);
		nowTime.setDate(nowTime.getDate() - 7);//设置前一周
		this.startTime=common.getTimeMmss(nowTime);
	}
	ngOnInit() {
		this.initTime();
		this.getAllAreaList();
		this.getStationByArea();
		this.load()
	}
	getAllAreaList(){
		this.jsonApiService.http("QRcodeStationManage/queryAllArea.html",'').subscribe(result => {
			this.allAreaList=result.data;
		})
	}
	getStationByArea(){
		let reqdata='areaName='+this.areaName;
		this.jsonApiService.http("QRcodeStationManage/queryStationByArea.html",reqdata).subscribe(result => {
			this.allStationList=result.data;
		})
	}

	//加载表格数据
	load() {
		var postData = {
			pageSize: this.pageSize,
			nowPage: this.curPage,
			parameters: {
				areaName:this.areaName,
				startTime:this.startTime,
				endTime:this.endTime,
				groupBy:'areaName'
			}
		}
		let reqdata = 'gridPager=' + JSON.stringify(postData);
		this.jsonApiService.http("clearDetail/detailpageGroup.html", reqdata).subscribe(data => {
			if(data.isSuccess) {
				this.tableData = data.exhibitDatas;
				this.totalCount = data.recordCount;
			}
		})
	}

	exportData() {
		let parameters = {
			areaName:this.areaName,
			startTime:this.startTime,
			endTime:this.endTime,
			groupBy:'areaName'
		};
		let timeCheck=common.correctTime(parameters, ['groupBy']);
		if(!timeCheck.status){
			this.jsonApiService.message(timeCheck.message);
			return;
		}
		let paramsName='param';
		let _url=config.BaseURL + 'clearDetail/exportClearDetailGroup.html';
		common.exprotDataFile(parameters,paramsName,_url);
	}

	//刷新
	refresh() {
		this.load();
	}
	//查询
	search_data() {
		this.searchKey = common.stringTrim(this.searchKey);
		this.load();
	}
	//模糊搜索
	table_search() {
		this.search_data();
	}
	//分页回调
	paginate(e) {
		this.curPage = e.page + 1;
		this.pageSize = e.rows;
		this.load();
	}
	ngOnDestroy() {
		document.onclick = null;
	}
}